| Total Complexity | 6 |
| Total Lines | 25 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | class Queue1 { |
||
| 2 | // put your code here to address problems |
||
| 3 | constructor(stack1, stack2) { |
||
| 4 | this.stack1 = stack1; |
||
| 5 | this.stack2 = stack2; |
||
| 6 | } |
||
| 7 | enqueue(record) { |
||
| 8 | // - Pop out all elements from Stack1, push to Stack2 |
||
| 9 | while (this.stack1.top()) { |
||
| 10 | this.stack2.push(this.stack1.pop()); |
||
| 11 | } |
||
| 12 | // - Push new record to Stack1 |
||
| 13 | this.stack1.push(record); |
||
| 14 | // - Pop out all elements from Stack2, push back to Stack1 |
||
| 15 | while (this.stack2.top()) { |
||
| 16 | this.stack1.push(this.stack2.pop()); |
||
| 17 | } |
||
| 18 | } |
||
| 19 | dequeue() { |
||
| 20 | return this.stack1.pop(); |
||
| 21 | } |
||
| 22 | peek() { |
||
| 23 | return this.stack1.data; |
||
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 59 |